home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / Mail / getname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-08  |  1.5 KB  |  60 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)getname.c    5.7 (Berkeley) 3/6/89";
  20. #endif /* not lint */
  21.  
  22. #include <sys/types.h>
  23. #include <pwd.h>
  24.  
  25. /*
  26.  * Getname / getuserid for those with
  27.  * hashed passwd data base).
  28.  *
  29.  */
  30.  
  31. #include "rcv.h"
  32.  
  33. /*
  34.  * Search the passwd file for a uid.  Return name through ref parameter
  35.  * if found, indicating success with 0 return.  Return -1 on error.
  36.  */
  37. char *
  38. getname(uid)
  39. {
  40.     struct passwd *pw;
  41.  
  42.     if ((pw = getpwuid(uid)) == NULL)
  43.         return NOSTR;
  44.     return pw->pw_name;
  45. }
  46.  
  47. /*
  48.  * Convert the passed name to a user id and return it.  Return -1
  49.  * on error.
  50.  */
  51. getuserid(name)
  52.     char name[];
  53. {
  54.     struct passwd *pw;
  55.  
  56.     if ((pw = getpwnam(name)) == NULL)
  57.         return -1;
  58.     return pw->pw_uid;
  59. }
  60.